package com.zjut.zs.user.manager;

import java.util.List;

import javax.annotation.Resource;

import com.zjut.an.util.module.PageModule;
import com.zjut.zs.cj.manager.ZsCjManager;
import com.zjut.zs.exvalue.manager.ZsExValueManager;
import com.zjut.zs.file.manager.ZsFileManager;
import com.zjut.zs.hjqk.manager.ZsHjqkManager;
import com.zjut.zs.pay.manager.ZsPayManager;
import com.zjut.zs.shhd.manager.ZsShhdManager;
import com.zjut.zs.user.dao.ZsUser;
import com.zjut.zs.user.dao.ZsUserDAO;
import com.zjut.zs.userinfo.manager.ZsUserinfoManager;
import com.zjut.zs.userstatus.manager.ZsUserStatusManager;
import com.zjut.zs.xy.manager.ZsXyManager;
import com.zjut.zs.zxlb.manager.ZsZxlbManager;


public class ZsUserManager {

	@Resource(name = "ZsUserStatusManager")
	private ZsUserStatusManager smanager;

	@Resource(name = "ZsUserinfoManager")
	private ZsUserinfoManager uimanager;

	@Resource(name = "ZsCjManager")
	private ZsCjManager cjmanager;

	@Resource(name = "ZsXyManager")
	private ZsXyManager xymanager;

	@Resource(name = "ZsZxlbManager")
	private ZsZxlbManager zxlbmanager;

	@Resource(name = "ZsHjqkManager")
	private ZsHjqkManager hjqkmanager;

	@Resource(name = "ZsShhdManager")
	private ZsShhdManager shhdmanager;

	@Resource(name = "ZsExValueManager")
	private ZsExValueManager evmanager;

	@Resource(name = "ZsFileManager")
	private ZsFileManager filemanager;
	
	@Resource(name = "ZsPayManager")
	private ZsPayManager paymanager;
	
	@Resource(name = "ZsUserDAO")
	private ZsUserDAO dao;
	
	
	public void addData(ZsUser obj) {	
		dao.save(obj);
	}
	
	public void updateData(ZsUser obj) {
		dao.update(obj);
	}
	
	public void deleteData(ZsUser obj) {
		try {
			this.deleteLinkData(obj);//删除关联
			dao.delete(obj);
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}

	public void deleteDatas(List<ZsUser> objlist) {
		for (ZsUser obj : objlist) {
			this.deleteData(obj);
		}
	}
	
	public PageModule getDataByInstance (int pageNumber,int pageSize, String sort, String order, ZsUser obj) {
		return dao.findByInstance(pageNumber, pageSize, sort, order, obj);
	}
	
	public List getDatas() {
		return dao.findAll();
	}

	public ZsUser getData(String usId) {
		return dao.findById(usId);
	}
	
	private void deleteLinkData(ZsUser user) {
		uimanager.deleteData(uimanager.getDataByUser(user));
		smanager.deleteData(smanager.getDataByUser(user));
		cjmanager.deleteData(cjmanager.getDataByUser(user));
		xymanager.deleteData(xymanager.getDataByUser(user));
		evmanager.deleteData(evmanager.getDataByUser(user));
		zxlbmanager.deleteDatas(zxlbmanager.getDataByUser(user));
		hjqkmanager.deleteDatas(hjqkmanager.getDataByUser(user));
		shhdmanager.deleteDatas(shhdmanager.getDataByUser(user));
		filemanager.deleteDatas(filemanager.getDataByUser(user));
		paymanager.deleteDatas(paymanager.getDatasByUser(user));
	}
}
